package com.newbingo.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.googlecode.jsonplugin.annotations.JSON;

import com.newbingo.dto.AgentDto;
import com.newbingo.dto.GameDto;
import com.newbingo.dto.GameRebateDto;
import com.newbingo.entity.Agent;
import com.newbingo.entity.Game;
import com.newbingo.entity.GameRebate;
import com.newbingo.service.imple.IGameRebateService;
import com.newbingo.service.imple.IGameService;
import com.newbingo.util.Pager;

import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;

public class GameRebateAction extends ActionSupport {

	/**
	 * GameRebateDto属性字段 
	 * Integer id; 
	 * Integer agentId; 
	 * Integer gameno; 
	 * String  gameName; 
	 * Integer amount; 
	 * Integer rebate; 
	 * String  startTime; 
	 * String  endTime;
	 */

	private IGameRebateService gameRebateService = null;
	private IGameService gameService = null;

	// 分页查询条件
	private Pager pager = null;
	private int start;
	private int limit = 15;

	// 实体和DTO对象
	private GameRebate rebate;
	private GameRebateDto gameRebateDto;

	private boolean success = false;

	// 新增传参
	private String gameName;
	private Integer gameno;
	private Integer id;

	private List<GameDto> gameDto = new ArrayList<GameDto>();

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getGameName() {
		return gameName;
	}

	public void setGameName(String gameName) {
		this.gameName = gameName;
	}

	/** *********操作方法************** */

	/*
	 * 增加
	 */
	public String create() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		AgentDto agentDto = (AgentDto) session.getAttribute("user");
		if (rebate != null) {
			Agent agent = new Agent();
			agent.setUno(agentDto.getUno());
			rebate.setAgent(agent);
			Game game = new Game();
			game.setGameno(gameno);
			rebate.setGame(game);
			gameRebateService.save(rebate);
			success = true;
		} else {
			success = false;
		}
		return SUCCESS;
		// return "create";
	}

	/*
	 * 修改
	 */
	public String update() {
		System.out.println(rebate.getId());
		System.out.println(rebate.getAmount());
		System.out.println(rebate.getStartTime());
		System.out.println(rebate.getEndTime());
		gameRebateService.merger(rebate);
		success = true;
		return SUCCESS;
		// return "update";
	}

	/*
	 * 删除
	 */
	public String delete() {
		gameRebateService.delete(rebate);
		success = true;
		return SUCCESS;
		// return "delete";
	}

	/*
	 * 查询
	 */
	public String findRebate() {
		HttpSession session = ServletActionContext.getRequest().getSession();
		AgentDto agentDto = (AgentDto) session.getAttribute("user");
		this.setGameDto(gameService.findAllDto());
		this.setPager(gameRebateService.findRebate(start, limit, agentDto
				.getUno(), gameName));
		success = true;
		return SUCCESS;
	}

	/*
	 * 获取单个对象
	 */
	public String getRebateObject() {
		this.setGameRebateDto(gameRebateService.findById(id));
		System.out.println(gameRebateDto.getGameName());
		System.out.println(gameRebateDto.getAmount());
		success = true;
		return SUCCESS;
		// return "merge";
	}

	@JSON(serialize = false)
	public IGameRebateService getGameRebateService() {
		return gameRebateService;
	}

	public void setGameRebateService(IGameRebateService gameRebateService) {
		this.gameRebateService = gameRebateService;
	}

	@JSON(serialize = false)
	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	@JSON(serialize = false)
	public GameRebate getRebate() {
		return rebate;
	}

	public void setRebate(GameRebate rebate) {
		this.rebate = rebate;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public GameRebateDto getGameRebateDto() {
		return gameRebateDto;
	}

	public void setGameRebateDto(GameRebateDto gameRebateDto) {
		this.gameRebateDto = gameRebateDto;
	}

	public IGameService getGameService() {
		return gameService;
	}

	public void setGameService(IGameService gameService) {
		this.gameService = gameService;
	}

	public List<GameDto> getGameDto() {
		return gameDto;
	}

	public void setGameDto(List<GameDto> gameDto) {
		this.gameDto = gameDto;
	}

	public Integer getGameno() {
		return gameno;
	}

	public void setGameno(Integer gameno) {
		this.gameno = gameno;
	}

}
